import DAYJS from "dayjs";
// 格式化时间
// format 的 格式 YYYY 年 MM 月 DD 日
// 例 YYYY-MM-DD MM/DD
const formatDay = (val, format) => {
  return DAYJS(val).format(format);
};
// 格式化时间
// 例 20180305105019
const formatDay_1 = (val, format) => {
  if (format == "YYYY-MM-DD") {
    return val.replace(/(\d{4})(\d{2})(\d{2})(\d*)/gi, "$1-$2-$3");
  }
};
// 格式化 卡号
// 6220 1234 1234 1234
const bankCard = (val) => {
  return val.replace(/(\d{4})/g, "$1 ").trim();
};
// 格式化 金额
const formatNumber = (val, NUMBER) => {
  let multiple = 1 + "0".repeat(NUMBER);
  return ((val * multiple) / multiple).toFixed(NUMBER);
};
// 格式化 手机号
const formatPhone = (val) => {
  return val.replace(/(\d{3})(\d{4})(\d{4})/g, "$1 **** $3 ").trim();
};
// 补齐
// @param a:填充物, b:before|after
// @return a+" "+value或value+" "+a;
const fill = (value, a, b) => {
  if (typeof value == undefined || typeof value == "undefined") {
    return "--";
  }
  if (b == "before") {
    return a + " " + value;
  } else if (b == "after") {
    return value + " " + a;
  }
};
// 开关
const replaceCn = (value) => {
  if (value === false || value === "false") {
    return "关";
  } else if (value === true || value === "true") {
    return "开";
  } else if (value === "warm" || value === "WARM") {
    return "热";
  } else if (value === "cool" || value === "COOL") {
    return "冷";
  } else {
    return value;
  }
};
export {
  formatDay,
  formatDay_1,
  bankCard,
  formatNumber,
  formatPhone,
  fill,
  replaceCn,
};
